package com.gitee.lougnib.hellowebim.module.chatroom.timer;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.SchedulingConfigurer;
import org.springframework.scheduling.config.ScheduledTaskRegistrar;

import com.gitee.lougnib.hellowebim.module.chatroom.service.ChatRoomService;

@EnableScheduling
@Configuration
public class ChatRoomMessageClearTask implements SchedulingConfigurer {

	@Autowired
	private ChatRoomService service;

	@Override
	public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
		taskRegistrar.addCronTask(() -> {
			service.removeOldMessages();
		}, "0 0 */1 * * ?"); // 定时 1 小时执行一次
	}
}

